package org.jeecg.modules.fund.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Dict;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.fund.entity.FundLibrary;
import org.jeecg.modules.fund.entity.FundList;
import org.jeecg.modules.fund.mapper.FundValMapper;
import org.jeecg.modules.fund.model.FundValLineModel;
import org.jeecg.modules.fund.service.IFundLibraryService;
import org.jeecg.modules.fund.service.IFundValService;
import org.jeecg.modules.fund.service.IFundValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Dictionary;
import java.util.List;
import java.util.Map;

@Deprecated
@RestController
@Api(tags = "基金更新")
@RequestMapping("/sys/fundVal")
@Slf4j
public class FundValController {
    @Autowired
    private IFundValService fundValService;
    @Autowired
    private FundValMapper fundValMapper;
    @Autowired
    private IFundValueService fundValueService;
    @Autowired
    private IFundLibraryService fundLibraryService;

    @RequestMapping(value = "/code", method = RequestMethod.GET)
    public void queryPageList() {
        fundValueService.batchUpdateLine60();
    }

    @RequestMapping(value = "/queryLine", method = RequestMethod.GET)
    public Result<List<Map<String, Object>>> queryLine(@RequestParam(name = "code", required = true) String code, @RequestParam(name = "str", required = true) String str) {
        FundValLineModel model = new FundValLineModel();
        model.setCode(code);

        Date date = new Date();
        // 格式化日期
        if ("近1月".equals(str)) {
            date = DateUtil.offsetDay(new Date(), -29);
            model.setStartDate(DateUtil.format(date, "yyyy-MM-dd"));
        } else if ("近3月".equals(str)) {
            date = DateUtil.offsetDay(new Date(), -89);
            model.setStartDate(DateUtil.format(date, "yyyy-MM-dd"));
        } else if ("近6月".equals(str)) {
            date = DateUtil.offsetDay(new Date(), -179);
            model.setStartDate(DateUtil.format(date, "yyyy-MM-dd"));
        } else if ("近1年".equals(str)) {
            date = DateUtil.offsetDay(new Date(), -365);
            model.setStartDate(DateUtil.format(date, "yyyy-MM-dd"));
        } else if ("近3年".equals(str)) {
            date = DateUtil.offsetDay(new Date(), -1095);
            model.setStartDate(DateUtil.format(date, "yyyy-MM-dd"));
        } else if ("近5年".equals(str)) {
            date = DateUtil.offsetDay(new Date(), -1825);
            model.setStartDate(DateUtil.format(date, "yyyy-MM-dd"));
        } else if ("今年来".equals(str)) {
            model.setStartDate(DateUtil.format(date, "yyyy") + "-01-01");
        }
        // 当前日期
        model.setEndDate(DateUtil.now());
        List<Map<String, Object>> data = fundValMapper.getLineList(model);
        return Result.OK(data);
    }

    @RequestMapping(value = "/queryWave", method = RequestMethod.GET)
    public Result<List<Dict>> queryWave(@RequestParam(name = "code", required = true) String code) {
        return Result.OK(fundValService.createWave(code));
    }
}
